﻿/*
#------------------------------------------------------------------------------
#-- View Name:		[dbo].[vwMaint_DoNotMaintain]
#-- Purpose:		Provides a table view of the CSV column [dbo].[tblMaint_Config].[cfg_maint_skip_db]
#--	Last Update:	01/30/2015
#--					For a complete history - please review comments in Version 
#--					Control
#------------------------------------------------------------------------------
*/
CREATE VIEW [dbo].[vwMaint_DoNotMaintain]
AS

SELECT		db.[name] [database_name]
FROM		(
			SELECT			skip_db.db.value('.', 'sysname') database_name
			FROM			(
							SELECT		CAST('<A>' + REPLACE(REPLACE([cfg_maint_skip_db], ' ', ''), ',', '</A><A>') + '</A>' AS XML) skip_db
							FROM		[dbo].[tblMaint_Config] (NOLOCK)
							) t1
			CROSS APPLY		skip_db.nodes('/A') skip_db(db)
			WHERE			LTRIM(RTRIM(skip_db.db.value('.', 'sysname'))) <> ''
			) nobkp
JOIN		sys.databases db ON db.[name] LIKE REPLACE(nobkp.[database_name], '*', '%')